package com.qijia.travel.app;

import java.math.BigDecimal;

import com.qijia.travel.domain.RewardProfit;
import com.qijia.travel.domain.StatisticsPojo;

public class FirstGuideTypeCounter implements RewardCounter {

	public BigDecimal countReward(StatisticsPojo detail,
			RewardProfit rewardProfit) {

		// 算出团均
		/*
		 * 团均 = 总创利合计 * 15% / 总团数
		 */
		BigDecimal groupJ = rewardProfit.getProfitTotal().multiply(
				rewardProfit.getProfitTotalPercent()).divide(
				new BigDecimal(rewardProfit.getTotalGroupNum()),
				BigDecimal.ROUND_HALF_EVEN);

		// 算出个人应得
		/*
		 * 个人应得 = 团均 * 个人团数 - 个人创利创利总计 * 15% - 个人奖励总计
		 */
		return groupJ.multiply(new BigDecimal(detail.getGroupNum())).subtract(
				detail.getProfitTotal().multiply(
						rewardProfit.getPersonProfitPercent())).subtract(
				detail.getRewardTotal()).setScale(2, BigDecimal.ROUND_HALF_UP);

	}
}
